package com.kungfuhacking.wristbandpro.my.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.kungfuhacking.wristbandpro.R;
import com.kungfuhacking.wristbandpro.base.view.BaseActivity;
import com.kungfuhacking.wristbandpro.custom.InputView;
import com.kungfuhacking.wristbandpro.my.bean.OldDetail;

/**
 * 修改老人姓名
 * Created by Aaron on 17/6/1.
 */

public class ModifyOldNameActivity extends BaseActivity implements View.OnClickListener {

    private InputView name;
    private OldDetail oldDetail;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_modify_name);
        initWidget();

        oldDetail = getIntent().getParcelableExtra("oldInfo");

        name.setTxt(oldDetail.getData().getChildName());

    }

    private void initWidget() {
        name = (InputView) findViewById(R.id.name);
        TextView tvright = (TextView) findViewById(R.id.tv_right);
//        TextView tvtitle = (TextView) findViewById(R.id.tv_title);
        ImageView ivleft = (ImageView) findViewById(R.id.iv_left);
        tvright.setText(getResources().getString(R.string.done));
        ivleft.setOnClickListener(this);
        tvright.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.iv_left:
                finish();
                break;
            case R.id.tv_right://完成

                if (TextUtils.isEmpty(name.getText())) {
                    showErr("请输入昵称");
                    return;
                }

                if (name.getText().equals(oldDetail.getData().getChildName())) {
                    finish();
                    return;
                }

                Intent data = new Intent();
                data.putExtra("name", name.getText());
                setResult(0x023, data);
                finish();
                break;
        }
    }


}
